﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TodayWhoModel;
using System.Data.SqlClient;
using System.Data;

namespace TodayWho
{
    public partial class search : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (!string.IsNullOrEmpty(Request.QueryString["s"]))
                {
                    DataTable dt = new DataTable();
                    dt.Load(UserModel.Search(Request.QueryString["s"]));
                    repeaterSearchResults.DataSource = dt;
                    repeaterSearchResults.DataBind();
                }
            }
        }

        protected void btnSearch_OnClick(object sender, EventArgs e)
        {
            if (ddlCategory.SelectedValue == "0")
            {
                DataTable dt = new DataTable();
                dt.Load(UserModel.Search(txtSearch.Text.Trim()));
                repeaterSearchResults.DataSource = dt;
                repeaterSearchResults.DataBind();
            }
            else
            {
                DataTable dt = new DataTable();
                dt.Load(UserModel.Search(txtSearch.Text.Trim(),Convert.ToInt32(ddlCategory.SelectedValue)));
                repeaterSearchResults.DataSource = dt;
                repeaterSearchResults.DataBind();
            }
        }
    }
}